package com.zp.business.controller.infusion;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.zp.business.entity.infusion.bo.InfusionRegisterStayBo;
import com.zp.business.entity.infusion.vo.InfusionPrescriptionVo;
import com.zp.business.entity.infusion.vo.InfusionRegisterStayVo;
import com.zp.business.entity.patient.vo.ClinicMasterVo;
import com.zp.business.service.infusion.IInfusionRegisterStayService;
import com.zp.common.core.controller.BaseController;
import com.zp.common.core.entity.R;
import com.zp.common.core.validate.AddGroup;
import com.zp.common.core.validate.EditGroup;
import com.zp.common.excel.utils.ExcelUtil;
import com.zp.common.log.annotation.Log;
import com.zp.common.log.enums.BusinessType;
import com.zp.common.myBatis.core.page.PageQuery;
import com.zp.common.myBatis.core.page.TableDataInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 输液室待登记控制器
 * 前端访问路由地址为:/business/infusionRegisterStay
 *
 * @author zhang peng
 * @ date 2025-02-02
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/infusionRegisterStay")
public class InfusionRegisterStayController extends BaseController {

    private final IInfusionRegisterStayService iInfusionRegisterStayService;

    /**
     * 查询输液室待登记列表 (分页)
     */
    @SaCheckPermission("business:infusionRegisterStay:list")
    @GetMapping("/selectPage")
    public TableDataInfo<InfusionRegisterStayVo> selectPage(InfusionRegisterStayBo bo, PageQuery pageQuery) {
        return iInfusionRegisterStayService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询输液室待登记列表 (不分页)
     */
    @SaCheckPermission("business:infusionRegisterStay:list")
    @GetMapping("/list")
    public R<List<InfusionRegisterStayVo>> list(InfusionRegisterStayBo bo) {
        List<InfusionRegisterStayVo> list = iInfusionRegisterStayService.queryList(bo);
        return R.ok(list);
    }

    /**
     * 查询待登记的输液患者项目明细列表
     */
    @GetMapping("/getInfusionRegisterStayItemList")
    public R<List<InfusionPrescriptionVo>> getInfusionRegisterStayItemList(InfusionRegisterStayBo bo) {
        List<InfusionPrescriptionVo> list = iInfusionRegisterStayService.getInfusionRegisterStayItemList(bo);
        return R.ok(list);
    }

    /**
     * 查询待登记的输液患者列表
     */
    @GetMapping("/getInfusionRegisterStayList")
    public TableDataInfo<ClinicMasterVo> getInfusionRegisterStayList(InfusionRegisterStayBo bo, PageQuery pageQuery) {
        return iInfusionRegisterStayService.getInfusionRegisterStayList(bo, pageQuery);
    }

    /**
     * 导出输液室待登记列表
     */
    @SaCheckPermission("business:infusionRegisterStay:export")
    @Log(title = "输液室待登记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(InfusionRegisterStayBo bo, HttpServletResponse response) {
        List<InfusionRegisterStayVo> list = iInfusionRegisterStayService.queryList(bo);
        ExcelUtil.exportExcel(list, "输液室待登记", InfusionRegisterStayVo.class, response);
    }

    /**
     * 获取输液室待登记详细信息
     *
     * @param infusionRegisterStayId 主键
     */
    @SaCheckPermission("business:infusionRegisterStay:list")
    @GetMapping("/{infusionRegisterStayId}")
    public R<InfusionRegisterStayVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable String infusionRegisterStayId) {
        return R.ok(iInfusionRegisterStayService.queryById(infusionRegisterStayId));
    }

    /**
     * 新增输液室待登记
     */
    @SaCheckPermission("business:infusionRegisterStay:add")
    @Log(title = "输液室待登记", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody InfusionRegisterStayBo bo) {
        return toAjax(iInfusionRegisterStayService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改输液室待登记
     */
    @SaCheckPermission("business:infusionRegisterStay:edit")
    @Log(title = "输液室待登记", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody InfusionRegisterStayBo bo) {
        return toAjax(iInfusionRegisterStayService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除输液室待登记
     *
     * @param infusionRegisterStayIds 主键串
     */
    @SaCheckPermission("business:infusionRegisterStay:remove")
    @Log(title = "输液室待登记", businessType = BusinessType.DELETE)
    @DeleteMapping("/{infusionRegisterStayIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable String[] infusionRegisterStayIds) {
        return toAjax(iInfusionRegisterStayService.deleteWithValidByIds(Arrays.asList(infusionRegisterStayIds), true) ? 1 : 0);
    }
}
